<?php
class database
{
	var $db;
	
	function connect()
	{
		$this->db = new mysqli("localhost", "root", "", "creative");
		if (mysqli_connect_errno() != 0)
        {
        	echo mysqli_connect_error();
            return false;
        }
		
		$this->db->query("SET NAMES 'utf8'");
		return true;
	}
	
	function getLastID()
	{
		return $this->db->insert_id;
	}
	
    function query($sql)
	{
		return $this->db->query($sql);
	}
	
	function safeQuery($sql)
	{							
		$arg_list = func_get_args();

		for ($i = 1; $i < func_num_args(); $i++) 
		{			
			$safe_variable = trim( addslashes( htmlspecialchars($arg_list[$i]) ) );			
			$sql = str_replace("{" . ($i-1) . "}", $safe_variable, $sql);
		}
		
		return $sql;		
	}
	
	function paramQuery($sql)
	{							
		$arg_list = func_get_args();

		for ($i = 1; $i < func_num_args(); $i++) 
		{			
			$safe_variable = trim( addslashes( $arg_list[$i] ) );			
			$sql = str_replace("{" . ($i-1) . "}", $safe_variable, $sql);
		}
		
		return $sql;		
	}
		
	function close()
	{
		$this->db->close();
	}
	
	function beginTransaction()
	{
		$this->db->query("BEGIN;");
	}
	
	function rollbackTransaction()
	{
		$this->db->query("ROLLBACK;");
	}
	
	function commitTransaction()
	{
		$this->db->query("COMMIT;");
	}
};
?>